# -*- coding: utf-8 -*-

"""
@Datetime: 2019/5/8
@Author: Zhang Yafei
"""
import tkinter
import random
import threading
import time
import pandas as pd


# 初始化窗口
root = tkinter.Tk()
root.title("随机名单")
root.geometry('500x700+400+200')
root.resizable(False, False)
root.flag = True

# 三个Lable标签
first = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
first.place(x=80, y=100, width=350, height=100)

second = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
second['fg'] = 'red'
second.place(x=80, y=200, width=350, height=100)

third = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
third['fg'] = 'red'
third.place(x=80, y=300, width=350, height=100)

four = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
four['fg'] = 'red'
four.place(x=80, y=400, width=350, height=100)

five = tkinter.Label(root, text='', font=("宋体", 20, "normal"))
five.place(x=80, y=500, width=350, height=100)


def get_names():
    df = pd.read_excel('names.xlsx')
    return df.姓名.values


students = get_names()


def switch():
    root.flag = True
    while root.flag:
        i = random.randint(0, len(students) - 1)
        first['text'] = second['text']
        second['text'] = third['text']
        third['text'] = four['text']
        four['text'] = five['text']
        five['text'] = students[i]
        time.sleep(0.1)


# 开始按钮
def butStartClick():
    t = threading.Thread(target=switch)
    t.start()


btnStart = tkinter.Button(root, text='开始', command=butStartClick)
btnStart.place(x=30, y=30, width=80, height=20)


# 结束按钮
def btnStopClick():
    root.flag = False


butStop = tkinter.Button(root, text='停止', command=btnStopClick)
butStop.place(x=160, y=30, width=80, height=20)


if __name__ == '__main__':
    # 启动主程序
    root.mainloop()
    # get_names()

